package acidcart.client;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
//import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ContactInfoView extends Composite {

	private final TextBox firstName;
	private final TextBox lastName;
	private final TextBox addressLine1;
	private final TextBox addressLine2;
	private final TextBox city;
	private final StateListBox state;
	private final TextBox zip;
	private final TextBox emailAddress;
	private final Button saveButton;
	private final Button cancelButton;

	public ContactInfoView()
	{
		// Decorator Panel is not looking right.
	    //DecoratorPanel decorator = new DecoratorPanel();
	    //initWidget(this);//decorator);
	    //decorator.setWidth("18em");
	    //decorator.setHeight("30em");

	    VerticalPanel contactInfoPanel = new VerticalPanel();
	    
		firstName = new TextBox();
		lastName = new TextBox();
		addressLine1 = new TextBox();
		addressLine2 = new TextBox();
		city = new TextBox();
		state = new StateListBox();
		zip = new TextBox();
		emailAddress = new TextBox();
	    
		FlexTable contactInfoTable = new FlexTable();
	    contactInfoTable.setWidget(0, 0, new Label("First Name"));
	    contactInfoTable.setWidget(0, 1, firstName);
	    contactInfoTable.setWidget(1, 0, new Label("Last Name"));
	    contactInfoTable.setWidget(1, 1, lastName);
	    contactInfoTable.setWidget(2, 0, new Label("Address Line 1"));
	    contactInfoTable.setWidget(2, 1, addressLine1);
	    contactInfoTable.setWidget(3, 0, new Label("Address Line 2"));
	    contactInfoTable.setWidget(3, 1, addressLine2);
	    contactInfoTable.setWidget(4, 0, new Label("City"));
	    contactInfoTable.setWidget(4, 1, city);
	    contactInfoTable.setWidget(5, 0, new Label("State"));
	    contactInfoTable.setWidget(5, 1, state);
	    contactInfoTable.setWidget(6, 0, new Label("Zip"));
	    contactInfoTable.setWidget(6, 1, zip);
	    contactInfoTable.setWidget(7, 0, new Label("Email Address"));
	    contactInfoTable.setWidget(7, 1, emailAddress);
	    firstName.setFocus(true);
	    contactInfoPanel.add(contactInfoTable);

	    HorizontalPanel buttonPanel = new HorizontalPanel();
	    cancelButton = new Button("Cancel");
	    saveButton = new Button("Save");
	    buttonPanel.add(cancelButton);
	    buttonPanel.add(saveButton);
	    contactInfoPanel.add(buttonPanel);
	    
	    initWidget(contactInfoPanel);
		//decorator.add(contactInfoPanel);
	}

	public HasValue<String> getFirstName() {
		return firstName;
	}
	public HasValue<String> getLastName() {
		return lastName;
	}
	public HasValue<String> getAddressLine1() {
		return addressLine1;
	}
	public HasValue<String> getAddressLine2() {
		return addressLine2;
	}
	public HasValue<String> getCity() {
		return city;
	}
	public HasValue<String> getState() {
		return state.getStateTextBox();
	}
	public HasValue<String> getZip() {
		return zip;
	}
	public HasValue<String> getEmailAddress() {
		return emailAddress;
	}	
	public HasClickHandlers getSaveButton() {
		return saveButton;
	}
	public HasClickHandlers getCancelButton() {
		return cancelButton;
	}
	public Widget asWidget() {
		return this;
	}

}
